<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/3
 * Time: 9:34
 */

namespace plugin\admin\app\controller\tool;


use plugin\admin\app\controller\CoreController;
use plugin\admin\app\model\Option;
use support\Request;
use support\Response;
use Webman\Captcha\CaptchaBuilder;
use Webman\Captcha\PhraseBuilder;

class IndexController extends CoreController
{
    /**
     * 验证码
     * @param Request $request
     * @param string $type
     * @return Response
     */
    public function captcha(Request $request): Response
    {
        $type= $request->input('type','login');
        $builder = new PhraseBuilder(4, 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ');
        $captcha = new CaptchaBuilder(null, $builder);
        $captcha->build(120);
        $request->session()->set("captcha-$type", strtolower($captcha->getPhrase()));
        $img_content = $captcha->get();
        return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
    }
}